package semiProject_army.mvc.beans;
 

 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import semiProject_army.mvc.beans.BoardBean;
import semiProject_army.mvc.connection.ConnectionProvider;
import semiProject_army.mvc.connection.JDBCManager;
 

 
public class BoardDAO { 
 
        
 
        private Connection conn = null;
 
        private PreparedStatement pstmt = null;
 
        private ResultSet rs = null;
 

 
        private static BoardDAO instance = new BoardDAO();      
 
        
 
        public static BoardDAO getInstance() {
 
                return instance;
 
        };      
 
        
 
        private BoardDAO() { }
 
        
 
        
 

 

 
        public int getfreeBoardCount() {
 
                
 
                String sqlCount = "SELECT COUNT(*) FROM FREEBOARD";
 
                System.out.println(sqlCount);
 
                int count = 0;
 

 
                try{
 
                        conn = ConnectionProvider.getConnection();
 
                        pstmt = conn.prepareStatement(sqlCount);
 
                        
 
                        rs = pstmt.executeQuery();
 
                        
 
                        while(rs.next()) {
 
                                count = rs.getInt(1);
 
                        }
 
                        
 
                } catch(Exception e) {
 
                        System.out.println("BoardDao - getfreeBoardCount()");
 
                        e.printStackTrace();
 
                        
 
                } finally {
 
                        JDBCManager.close(rs, pstmt, conn);
 
                }
 

 
                return count;
 
        }
 
        
 
        
 

 
        public ArrayList<BoardBean> getBoardList(int startRow, int num) {
 
                
 
                String boardListSql = "SELECT * FROM freeboard order by no DESC limit ?, ?";
 
                ArrayList<BoardBean> fbList = null;
 
                
 
                try{
 
                        conn = ConnectionProvider.getConnection();
 
                        pstmt = conn.prepareStatement(boardListSql);
 
                        pstmt.setInt(1, startRow);
 
                        pstmt.setInt(2, num); 
